import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class DatabaseInterface {
	Connection conn = null;
	String url = "jdbc:mysql://localhost:3306/";
	String dbName = "test";
	String driver = "com.mysql.jdbc.Driver";
	String userName = "root";
	String password = "";
	
	public void connect(){
		try {
			Class.forName(driver).newInstance();
			conn = DriverManager
					.getConnection(url + dbName, userName, password);
			System.out.println("Connected to the database");

		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void printReferences(){
		try{
			Statement st = conn.createStatement();
			 ResultSet res = st.executeQuery("SELECT * FROM  References");
			 System.out.println("References:");
			 while (res.next()) {
				 String s = res.getString("value");
				 System.out.println(s);
			 }
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void printMatchingReferences(String ref){
		try{
			Statement st = conn.createStatement();
			 ResultSet res = st.executeQuery("SELECT * FROM  References Where 'value' = '" + ref + "'");
			 System.out.println("References for "+ ref);
			 while (res.next()) {
				 String type = res.getString("type");
				 String link = res.getString("link");
				 System.out.println(": " + type + " : " + link);
			 }
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void insertReference(String value, String type, String link){
		
	}
	

}
